{include file="common/_header"}
{include file="common/_header1"}

<body class="layui-anim layui-anim-up">
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:left;background: #00a0e9"
       href="javascript:location.replace('/products/shopsproduct');" title="返回">
        <i class="layui-icon" style="line-height:30px">&#xe65c;</i></a>
    <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">商品管理</a>
            <a><cite>商铺商品管理</cite></a>
            <a><cite>商品图库管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe669;</i></a>

</div>

<div class="x-body">

    <xblock>
        <!--            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <button class="layui-btn" onclick="x_admin_show('添加图片','/products/boxeimage?image_id=0&product_id={$product.product_id}',600,500)"><i class="layui-icon"></i>  添 加</button>
        <!--            <span class="x-right" style="line-height:40px">共有数据：88 条</span>-->
    </xblock>

    <table id="tables" class="layui-table">
        <thead>
        <tr>
            <th>图片</th>
            <th>排序</th>
            <th>是否显示</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data.images" id="vo"}
        <tr class="table_tr">
            <td><img src="/{$vo.url}"></td>
            <td>{$vo.sort}</td>
            <td>{if $vo.is_show == 1}<span class="status_span">显示</span>{else /} <span class="status_span_2">不显示</span> {/if}</td>
            <td>
                <ul class="nav navbar-nav" style=" height: 40px; line-height: 10px;">
                    <li class="dropdown" style="height: 100%;">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" style=" height: 100%; line-height: 5px;">
                            操作
                            <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a title="编辑图片"  onclick="x_admin_show('编辑图片', '/products/boxeimage?image_id={$vo.image_id}&product_id={$product.product_id}', '600', '500')" href="javascript:;">图片编辑</a></li>
                            <li class="divider"></li>
<!--                            <li><a title="删除" onclick="OperateDel('delstock?stock_id={$vo.image_id}')" href="javascript:;">删除</a></li>-->
                            <li>
                                {if $vo.is_show == 1}
                                <a title="不显示" onclick="opreate('{$vo.image_id}','不显示')" href="javascript:;">不显示</a>
                                {else /}
                                <a title="显示" onclick="opreate('{$vo.image_id}','显示')" href="javascript:;">显示</a>
                                {/if}
                            </li>
                        </ul>
                    </li>
                </ul>
            </td>

        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page_all">
        {$page|raw}
    </div>
</div>
<script>


    $(function () {
        // 表格选中行的同时选中单选框
        $("#tables tr:gt(0)").click(function () {
            $(this).find(":radio").prop("checked", true);
        });

    });

    //js放到table下，才能检测到tr数组
    var trs = document.getElementById("tables").getElementsByTagName("tr");
    $(function () {
        for (var i = 0; i < trs.length; i++) {
            trs[i].onmousedown = function () {
                mousedownclick(this);
            }
        }
    });

    function mousedownclick(obj) {
        for (var j = 0; j < trs.length; j++) {
            if (trs[j] == obj) {
                if (trs[0] != obj) {
                    trs[j].style.background = '#D0E9C6';
                    // 启用新增和编辑按钮
                    $("#edits").removeAttr("disabled");//启用按钮
                    $('#edits').removeClass('layui-disabled');
                }
            } else {
                trs[j].style.background = '';
            }
        }
    }


    function opreate(id,tip) {
        layer.confirm('您确定要'+tip+'该图片吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
            $.ajax({
                url: 'showimage?imageid=' + id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 500,
                    }, function () {
                        window.location.reload();
                    })
                }
            })
        });
    }
</script>
</body>

{include file="common/_bottom"}